Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var _util = _interopRequireDefault(require("../public/utils/util"));

function _interopRequireDefault(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function _classCallCheck(e, t) {
    if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function");
}

function _defineProperties(e, t) {
    for (var i = 0; i < t.length; i++) {
        var r = t[i];
        r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), 
        Object.defineProperty(e, r.key, r);
    }
}

function _createClass(e, t, i) {
    return t && _defineProperties(e.prototype, t), i && _defineProperties(e, i), e;
}

var strategies = {
    isNonEmpty: function(e, t) {
        if ("" === e) return t;
    },
    isMobile: function(e, t) {
        if (!_util.default.isMobile(e)) return t;
    },
    isVerifyCode: function(e, t) {
        if (!_util.default.isVerifyCode(e)) return t;
    },
    isEmail: function(e, t) {
        if (!_util.default.isEmail(e)) return t;
    }
}, Validator = function() {
    function e() {
        _classCallCheck(this, e), this.cache = [];
    }
    return _createClass(e, [ {
        key: "add",
        value: function() {
            var n = this, t = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", e = 1 < arguments.length ? arguments[1] : void 0, i = 2 < arguments.length ? arguments[2] : void 0, r = function(t, e, i) {
                var r = e.split(",");
                n.cache.push(function() {
                    var e = r.shift();
                    return r.unshift(t.trim()), r.push(i), strategies[e].apply(null, r);
                });
            };
            Array.isArray(e) ? e.map(function(e) {
                return r(t, e.strategy, e.errMsg);
            }) : "string" == typeof e && r(t, e, i);
        }
    }, {
        key: "start",
        value: function() {
            for (var e, t = 0; e = this.cache[t++]; ) {
                var i = e();
                if (i) return i;
            }
        }
    } ]), e;
}(), _default = Validator;

exports.default = _default;